#!/bin/bash
SCRIPT_BASE_DIR=$( dirname "${BASH_SOURCE[0]}" )
source "${SCRIPT_BASE_DIR}/common/fs_utils.sh"

cmd=$( basename "$0" )

function usage() {
	echo "Usage: ${cmd} [ -p | -h |-e]"
    echo -e "\t-p: 增加对父目录的cmake文件的索引"
    echo -e "\t-h: 显示帮助信息"
	exit 1
}

# 默认不增加对外部依赖项目的索引
indexParent=false
while getopts "ph" args
do
    case "${args}" in 
        p)
            indexParent=true
            ;;
        *)
            usage;;
    esac
done

csFile="cscope.files"

echo "Build ${csFile} ..."
find .  -name "*.cmake" > "${csFile}"
find .  -name CMakeLists.txt >> "${csFile}"

if ${indexParent}
then
    find ..  -maxdepth 1 -name CMakeLists.txt >> "${csFile}"
fi

echo "Build cscope DB..."
cscope -Rbqk
echo "Done."
